#pragma once
#include <iostream>
#include <pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t *pmtx) : _pmtx(pmtx) {}
    ~Mutex() {}
    void lock()
    {
        pthread_mutex_lock(_pmtx);
    }
    void unlock()
    {
        pthread_mutex_unlock(_pmtx);
    }

private:
    pthread_mutex_t *_pmtx;
};

class lockGuard // RAII式加锁解锁
{
public:
    lockGuard(pthread_mutex_t *pmtx) : mtx(pmtx)
    {
        mtx.lock();
    }
    ~lockGuard()
    {
        mtx.unlock();
    }

private:
    Mutex mtx;
};
